#include "EditorCore/Tools/SelectTool.h"
#include "EditorCore/IEntity.h"
#include "EditorCore/Actions/DeleteAction.h"
#include "EditorCore/Actions/SelectAction.h"
#include "EditorCore/Visitors/EntityUnderPositionFinder.h"

using namespace cmn;
using namespace input;

namespace editor_core {

	SelectTool::SelectTool( IDocument* document ) :
		m_document( document )
	{}

	SelectTool::~SelectTool() {}

	IAction* SelectTool::Activate() { return 0; }
	IAction* SelectTool::Deactivate() { return 0; }

	IAction* SelectTool::ProcessMouseButtonPress( MouseButtonEventArgs* mouseButtonEventArgs ) {
		if( mouseButtonEventArgs->GetButton() == MouseButton::Left ) {
			Vec2 mousePos = mouseButtonEventArgs->GetMouseState().GetPosition();

			IEntity* pressedEntity = EntityUnderPositionFinder::FindEntityUnderCursor( m_document->GetRootEntity(), mousePos );

			return new SelectAction( m_document->GetSelector(), pressedEntity );
		}
		return 0;
	}

	IAction* SelectTool::ProcessKeyPress( KeyEventArgs* keyEventArgs ) {
		if( m_document->GetSelector()->GetSelectedEntity() != 0 && keyEventArgs->GetKey() == 8 ) {
			return new DeleteAction( m_document->GetSelector()->GetSelectedEntity() );
		}
		return 0;
	}
	IAction* SelectTool::ProcessKeyRelease( KeyEventArgs* keyEventArgs ) { return 0; }

	IAction* SelectTool::ProcessMouseButtonRelease( MouseButtonEventArgs* mouseButtonEventArgs ) { return 0; }
	IAction* SelectTool::ProcessMouseMove( MouseMoveEventArgs* mouseMoveEventArgs ) { return 0; }
	IAction* SelectTool::ProcessMouseScroll( MouseScrollEventArgs* mouseScrollEventArgs ) { return 0; }
}
